<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/8/24
 * Time: 上午11:32
 */

namespace app\common\controller;


use think\Config;
use think\Controller;

class ActionLogs extends Controller
{
    /* $obj 项目
    *  $action 方法
    *  $data 数据
     * $model 模型
     * $other 备注
     *
    */

    public function writelog($obj,$model,$action,$other,$data){
        try{
            $cfg =Config::get('actionlog');
            $dir_path=$cfg.DS.$obj.DS.$model.DS.$action.DS;
            if(!is_dir($dir_path)){
                mkdir($dir_path,0777,true);
            }
            $filename=$dir_path.date('Y-m-d').".log";
            file_put_contents($filename,'['.date('Y-m-d H:i:s').']'.$other.json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
        } catch (\Exception $e) {
            $filename = ['errcode' => 9999, 'message' => $e->getMessage()];
        }
        return $filename;
    }
}